package logic_setting_menu

import (
	v1 "Sailor/app/Sailor-console-server/api/api_setting_menu/v1"
	"Sailor/app/Sailor-console-server/internal/dao"
	"Sailor/app/Sailor-console-server/internal/model/do"
	"context"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/google/uuid"
)

func (s *sSettingMenu) LogicSettingMenuCreate(ctx context.Context, req *v1.SettingMenuCreateReq) (res *v1.SettingMenuCreateRes, err error) {

	uid, err := uuid.NewV7()
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("创建失败")
	}
	_, err = dao.SysMenu.Ctx(ctx).Insert(do.SysMenu{
		Uuid:         uid.String(),
		MenuParentId: req.MenuParentId,
		MenuSort:     req.MenuSort,
		Path:         req.Path,
		Name:         req.Name,
		Redirect:     req.Redirect,
		Component:    req.Component,
		Icon:         req.MetaInfo.Icon,
		Title:        req.MetaInfo.Title,
		Active:       req.MetaInfo.Active,
		Type:         req.MetaInfo.MenuType,
		IsHide:       req.MetaInfo.Hidden,
		IsFull:       req.MetaInfo.Fullpage,
		IsAffix:      req.MetaInfo.Affix,
		IsKeepAlive:  req.MetaInfo.KeepAlive,
		Tag:          req.MetaInfo.Tag,
	})
	if err != nil {
		g.Log().Error(ctx, err)
		return nil, gerror.New("创建失败")
	}

	return &v1.SettingMenuCreateRes{
		Uuid: uid.String(),
	}, nil
}
